/*
 * @Author: 高瑞寒 15932717091@163.com
 * @Date: 2022-06-01 13:32:17
 * @LastEditTime: 2022-06-01 13:52:45
 * @LastEditors: 高瑞寒 15932717091@163.com
 * @Description: 
 */
function a() {
  console.log(this);
}

Function.prototype.myCall = function (context) {
  if (typeof this !== 'function') {
    throw new TypeError('类型错误')
  }
  // 判断是否传入参数
  context = context ?? globalThis
  // 存储当前函数实例
  context.fn = this
  // 截取除this外的所有参数
  const args = [...arguments].splice(1)
  // 截取的参数传入存储的函数实例并赋值给 result
  const result = context.fn(...args)
  // 删除存储的函数
  delete context.fn
  
  return result
}

const obj = {
  b: 1
}
a.myCall(obj, obj.b)

